package moplayer;

import java.util.HashMap;

public class ContinousPlayerRT extends Thread {

	TrackRT track;
	MyPlayerModel player;
	NoteRT lastNote;
	boolean locked;
	int channel = 5;
	boolean lock;
	String commandController;
	int count;

	public ContinousPlayerRT(RhythmTrack track, MyPlayerModel player, String commandControler) {
		this.track = track;
		this.player = player;
		this.commandController = commandControler;
	}

	public ContinousPlayerRT(HarmonyTrack track, MyPlayerModel player, String commandControler) {
		this.track = track;
		this.player = player;
		this.commandController = commandControler;
	}

	public void setChannel(int channel) {
		this.channel = channel;
	}

	@Override
	public void run() {
		while (!isInterrupted()) {
			if (track instanceof RhythmTrack) {
				RhythmTrack rt = (RhythmTrack) track;
				NoteRT note = rt.getNoteToPlay();
				HashMap<String, Boolean> toggleMap = DeviceValueOSCFiller.toggleMap;
				Boolean boolean1 = toggleMap.get(commandController);
				if (boolean1) {
					player.playNote(note, channel);
				} else {
					player.pause(note.getDuration());
				}

				// if (DeviceValueOSCFiller.command.equals("/buttonZPressed") &&
				// !lock) {
				// System.out.println("aqui!");
				// track.setIndexCell((count++) % 2);
				// lock = true;
				// } else if
				// (DeviceValueOSCFiller.command.equals("/buttonZReleased")) {
				// lock = false;
				// }
				if (DeviceValueOSCFiller.toggleMap.get("/buttonZ")) {
					rt.setIndexCell(0);
				} else {
					rt.setIndexCell(1);
				}
			} else if (track instanceof HarmonyTrack) {
				HarmonyTrack ht = (HarmonyTrack) track;
				HashMap<String, Boolean> toggleMap = DeviceValueOSCFiller.toggleMap;
				Boolean boolean1 = toggleMap.get(commandController);
				ChordRT chord = ht.getChordToPlay();
				if (boolean1) {
					player.playChord(chord, channel);
				} else {
					player.pause(chord.getDuration());
				}
			}
		}
	}
}
